import GLabel from 'wklabel';

/**
 * 点实心点对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Feature.Point} 点对象实例
 */
export const createFeaturePoint = gprops => {
    const {id = 'point-feature', shape = {}, props = {}, style = {}} = gprops || {};
    const featurePoint = new GLabel.Feature.Point(
        id, // id
        {sr: 3, ...shape}, // shape
        props, // props
        {fillStyle: '#1269db', ...style} // style
    );
    return featurePoint;
};

/**
 * 线对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Feature.Line} 线对象实例
 */
export const createFeatureline = gprops => {
    const {id = 'line-feature', shape = {}, props = {}, style = {}} = gprops || {};
    const featureLine = new GLabel.Feature.Line(
        id, // id
        {start: {}, end: {}, width: 3, ...shape}, // shape
        props, // props
        {strokeStyle: '#1269db', lineCap: 'round', ...style} // style
    );
    return featureLine;
};

/**
 * 多线段对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Feature.Polyline} 多线段对象实例
 */
export const createFeaturePolyLine = gprops => {
    const {id = 'polyline-feature', shape = {}, props = {}, style = {}} = gprops || {};
    const featurePolyline = new GLabel.Feature.Polyline(
        id, // id
        {width: 3, ...shape}, // shape
        props, // props
        {strokeStyle: '#1269db', lineCap: 'round', ...style} // style
    );
    return featurePolyline;
};

/**
 * 矩形对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Feature.Rect} 矩形对象实例
 */
export const createFeatureRect = gprops => {
    const {id = 'rect-feature', shape = {}, props = {}, style = {}} = gprops || {};
    const featureRect = new GLabel.Feature.Rect(
        id, // id
        shape, // shape
        props, // props
        {strokeStyle: '#1269db', lineWidth: 3, ...style} // style
    );
    return featureRect;
};

/**
 * 多边形对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Feature.Polygon} 多边形对象实例
 */
export const createFeaturePolygon = gprops => {
    const {id = 'polygon-feature', shape = {}, props = {}, style = {}} = gprops || {};
    const featurePolygon = new GLabel.Feature.Polygon(
        id, // id
        {points: [], ...shape}, // shape
        props, // props
        {strokeStyle: '#1269db', lineWidth: 3, ...style} // style
    );
    return featurePolygon;
};

/**
 * 圆形对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Feature.Circle} 圆形对象实例
 */
 export const createFeatureCircle = gprops => {
    const {id = 'circle-feature', shape = {}, props = {}, style = {}} = gprops || {};
    const featureCircle = new GLabel.Feature.Circle(
        id, // id
        shape,
        props, // props
        style // style
    );
    return featureCircle;
};

/**
 * 标记对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @return {GLabel.Marker} 标记对象实例
 */
export const createMarker = gProps => {
    const {id = 'marker-feature', shape = {}, props = {}} = gProps || {};
    const marker = new GLabel.Marker(
        id,
        {
            position: { // marker坐标位置
                x: 0,
                y: 0
            },
            offset: {
                x: -16,
                y: 32
            },
            ...shape
        },
        props
    );
    return marker;
};

/**
 * 涂抹对象
 * @param {String} id 挂载元素的id
 * @param {String} category 当前action类型
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Mask.Draw} 标记对象实例
 */
export const createDrawer = gProps => {
    const {id = 'drawer-feature', category = '铅笔', shape = {}, props = {}, style = {}} = gProps || {};
    const drawMaskAction = new GLabel.Mask.Draw(
        id,
        category,
        shape,
        props,
        {strokeStyle: '#FF0000', ...style} // style
    );
    return drawMaskAction;
};

/**
 * 擦除对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Mask.Clear} 标记对象实例
 */
export const createClear = gProps => {
    const {id = 'clear-feature', shape = {}, props = {}, style = {}} = gProps || {};
    const clearMaskAction = new GLabel.Mask.Clear(
        id, // id
        shape, // shape
        props,
        style
    );
    return clearMaskAction;
};

/**
 * 图片对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置形状参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Mask.Image} 标记对象实例
 */
export const createImage = gProps => {
    const {id = 'image-feature', category = '钢笔', shape = {}, props = {}, style = {}} = gProps || {};
    const image = new GLabel.Mask.Image(
        id,
        category,
        shape,
        props,
        style
    );
    return image;
};

/**
 * 文本对象
 * @param {String} id 挂载元素的id
 * @param {Object} shape 位置参数
 * @param {Object} props 自定义携带参数
 * @param {Object} style 样式
 * @return {GLabel.Text} 文本对象实例
 */
export const createText = gProps => {
    const {id = 'text-feature', shape = {}, props = {}, style = {}} = gProps || {};
    const text = new GLabel.Text(
        id,
        shape,
        props,
        style
    );
    return text;
};